package com.mercury.coffee.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mercury.coffee.entity.CoffeeCommentInfo;
import com.mercury.coffee.entity.PushCoffeeComments;
import com.mercury.coffee.service.PushCoffeeCommentsService;
import com.mercury.util.R;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 童雅婷
 * @since 2021-11-21
 */
@RestController
@RequestMapping("/coffee/comments")
public class PushCoffeeCommentsController {
    @Autowired
    private PushCoffeeCommentsService commentsService;

    @GetMapping("/getCommentsByCoffee/{id}")
    @ApiOperation("根据咖啡豆的id获取评论")
    public R getCommemtsByCoffee(@PathVariable int id){
        List<CoffeeCommentInfo> list = commentsService.getCommentByCoffee(id);
        return R.ok().data("comments",list);
    }

    @GetMapping("/getCommentsByUer/{id}")
    @ApiOperation("根据用户获取他的评论")
    public R getCommemtsByUser(@PathVariable String id){
        List<CoffeeCommentInfo> list = commentsService.getCommentByUser(id);
        return R.ok().data("comments",list);
    }

    @PostMapping("/pushComment")
    @ApiOperation("用户添加评论")
    public R pushComment(@RequestBody PushCoffeeComments coffeeComments) {
        boolean save = commentsService.save(coffeeComments);
        if(save) return R.ok().message("添加成功");
        else return R.error().message("添加失败");
    }

    //TODO 咖啡豆的评分
    //TODO 咖啡豆的各项得分，计算咖啡豆的各项得分，计算用户的雷达图

}

